

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="若发现文章有误，欢迎提出宝贵建议，望不吝指教，感谢!@[TOC]  运行环境  Ubuntu 21.04 Docker 20.10.7  一、Docker Volumes 相关概述 Docker官方说明文档 卷就是目录或文件，存在于一个或多个容器中，由docker挂载到容器，但不属于联合文件系统，因此能够绕过Union File System提供一些用于持续存储或共享数据的特性： 卷的设计目的">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker 笔记1 Volumes 卷的作用与案例 _ Docker安装常见服务 _ Tomcat &amp; MySQL">
<meta property="og:url" content="http://example.com/2022/04/04/Docker%20%E7%AC%94%E8%AE%B01%20Volumes%20%E5%8D%B7%E7%9A%84%E4%BD%9C%E7%94%A8%E4%B8%8E%E6%A1%88%E4%BE%8B%20_%20Docker%E5%AE%89%E8%A3%85%E5%B8%B8%E8%A7%81%E6%9C%8D%E5%8A%A1%20_%20Tomcat%20&%20MySQL/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="若发现文章有误，欢迎提出宝贵建议，望不吝指教，感谢!@[TOC]  运行环境  Ubuntu 21.04 Docker 20.10.7  一、Docker Volumes 相关概述 Docker官方说明文档 卷就是目录或文件，存在于一个或多个容器中，由docker挂载到容器，但不属于联合文件系统，因此能够绕过Union File System提供一些用于持续存储或共享数据的特性： 卷的设计目的">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/80f01d65c82d45559868e087cb16bfce.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/868b30f6b8444dcfb0dd9980ce8c1101.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/3185ce5b38c74c3081ae7254e69b2f33.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/5ed571ccbdac483680e2ae77fa7028e6.png">
<meta property="article:published_time" content="2022-04-04T01:44:48.000Z">
<meta property="article:modified_time" content="2022-08-22T15:43:01.619Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="Docker">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/80f01d65c82d45559868e087cb16bfce.png#pic_center">
  
  
  
  <title>Docker 笔记1 Volumes 卷的作用与案例 _ Docker安装常见服务 _ Tomcat &amp; MySQL - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Docker 笔记1 Volumes 卷的作用与案例 _ Docker安装常见服务 _ Tomcat &amp; MySQL"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-04-04 09:44" pubdate>
          2022年4月4日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          5.8k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          49 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Docker 笔记1 Volumes 卷的作用与案例 _ Docker安装常见服务 _ Tomcat &amp; MySQL</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p><img src="https://img-blog.csdnimg.cn/80f01d65c82d45559868e087cb16bfce.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<blockquote>
<p>若发现文章有误，欢迎提出宝贵建议，望不吝指教，感谢!<br>@[TOC]</p>
</blockquote>
<h1 id="运行环境"><a href="#运行环境" class="headerlink" title="运行环境"></a>运行环境</h1><hr>
<ul>
<li>Ubuntu 21.04</li>
<li>Docker 20.10.7</li>
</ul>
<h1 id="一、Docker-Volumes-相关概述"><a href="#一、Docker-Volumes-相关概述" class="headerlink" title="一、Docker Volumes 相关概述"></a>一、Docker Volumes 相关概述</h1><hr>
<p><a target="_blank" rel="noopener" href="https://docs.docker.com/storage/volumes/">Docker官方说明文档</a></p>
<p>卷就是目录或文件，存在于一个或多个容器中，由docker挂载到容器，但不属于联合文件系统，因此能够绕过Union File System提供一些用于持续存储或共享数据的特性：</p>
<p>卷的设计目的就是<strong>数据的持久化</strong>，完全独立于容器的生存周期，因此Docker<strong>不会</strong>在容器删除时删除其挂载的数据卷</p>
<p>卷的特点：</p>
<ul>
<li>易备份或迁移</li>
<li>适用于Linux和Windows容器</li>
<li>卷中的更改可以直接实时生效</li>
<li>数据卷中的更改不会包含在镜像的更新中</li>
<li>可在多个容器之间更安全的共享</li>
<li>数据卷的生命周期一直持续到没有容器使用它为止</li>
</ul>
<p><img src="https://img-blog.csdnimg.cn/868b30f6b8444dcfb0dd9980ce8c1101.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>（图片转自Docker官方）</p>
<h2 id="1-1-Docker-容器与宿主机共用卷案例"><a href="#1-1-Docker-容器与宿主机共用卷案例" class="headerlink" title="1.1 Docker 容器与宿主机共用卷案例"></a>1.1 Docker 容器与宿主机共用卷案例</h2><p>首先根据一个镜像创建容器来进行测试，笔者这里采用官方ubuntu的镜像</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker pull ubuntu</span><br></code></pre></td></tr></table></figure>

<p>创建新容器<br>标准语法：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">docker run -it --privileged=<span class="hljs-literal">true</span> -v /宿主机绝对路径目录:/容器内目录 镜像名</span><br></code></pre></td></tr></table></figure>
<p><code>提示：-v参数就是-volumes（卷）的缩写</code><br>案例：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker run -it --privileged=<span class="hljs-literal">true</span> -v /tmp/host_data:/tmp/docker_data --name=ubuntu_test ubuntu</span><br></code></pre></td></tr></table></figure>

<p>进入容器后，宿主机另开一个终端，进行简单的测试</p>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/5032865d37b1486b9256afc52c2e26f7.png#">https://img-blog.csdnimg.cn/5032865d37b1486b9256afc52c2e26f7.png#</a> &#x3D;80%x)</p>
<p>查看容器数据卷挂载情况</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker inspect ubuntu_test</span><br></code></pre></td></tr></table></figure>
<p>在输出的结果里查找<code>Mounts</code>属性<br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/ca5ca06eb0614185af1d88942d6d3d18.png#">https://img-blog.csdnimg.cn/ca5ca06eb0614185af1d88942d6d3d18.png#</a> &#x3D;50%x)</p>
<p>比如这里就是之前配置过后的容器卷，默认的容器卷如下（为空）：<br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/d4d71d361c5c43c0bacc60891d962e8a.png#">https://img-blog.csdnimg.cn/d4d71d361c5c43c0bacc60891d962e8a.png#</a> &#x3D;30%x)</p>
<h2 id="1-2-容器卷配置"><a href="#1-2-容器卷配置" class="headerlink" title="1.2 容器卷配置"></a>1.2 容器卷配置</h2><p>对于之前通过镜像绑定卷创建容器的命令，其实默认了一个配置，即对数据卷的读写权限</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">docker run -it --privileged=<span class="hljs-literal">true</span> -v /宿主机绝对路径目录:/容器内目录 镜像名</span><br></code></pre></td></tr></table></figure>

<p>补全配置后（后缀添加的:rw表示支持读和写）：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">docker run -it --privileged=<span class="hljs-literal">true</span> -v /宿主机绝对路径目录:/容器内目录:rw 镜像名</span><br></code></pre></td></tr></table></figure>

<p>当需求为Docker容器只能读取宿主机的数据卷，而容器不能写时，则在后面指定为ro即可，标准语法如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">docker run -it --privileged=<span class="hljs-literal">true</span> -v /宿主机绝对路径目录:/容器内目录:ro 镜像名</span><br></code></pre></td></tr></table></figure>

<h2 id="1-3-卷的继承和共享"><a href="#1-3-卷的继承和共享" class="headerlink" title="1.3 卷的继承和共享"></a>1.3 卷的继承和共享</h2><p>基于之前的<code>ubuntu_test</code>容器案例，我们现在创建一个容器<code>ubuntu_child</code>来继承它的数据卷机制</p>
<p>标准语法：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker run -it --privileged=<span class="hljs-literal">true</span> --volumes-from 父类容器 --name 子容器名称 镜像</span><br></code></pre></td></tr></table></figure>
<p>注：这里只是继承父容器的卷规则，而不是整个镜像，所以可以选择不同于父类的镜像。</p>
<p>案例：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker run -it --privileged=<span class="hljs-literal">true</span> --volumes-from ubuntu_test --name ubuntu_child ubuntu</span><br></code></pre></td></tr></table></figure>

<p><strong>注：</strong>创建后的子容器和父容器互不影响，父容器有没有启动并<strong>不会影响</strong>子容器去读取卷的文件内容</p>
<h1 id="二、Docker-常用安装案例"><a href="#二、Docker-常用安装案例" class="headerlink" title="二、Docker 常用安装案例"></a>二、Docker 常用安装案例</h1><hr>
<p>Docker 启动容器的常见步骤：</p>
<p>搜索镜像 -&gt; 拉取镜像 -&gt; 查看镜像 -&gt; 启动镜像 -&gt; 停止容器 -&gt; 移除容器</p>
<p>Docker Hub 官方网址：<a target="_blank" rel="noopener" href="https://hub.docker.com/">https://hub.docker.com/</a></p>
<h2 id="2-1-Docker-安装-Tomcat"><a href="#2-1-Docker-安装-Tomcat" class="headerlink" title="2.1 Docker 安装 Tomcat"></a>2.1 Docker 安装 Tomcat</h2><p><strong>查找镜像，拉取镜像到本地</strong></p>
<p>搜索镜像有两种方式，第一种是通过Docker Hub 官方网址<br><img src="https://img-blog.csdnimg.cn/3185ce5b38c74c3081ae7254e69b2f33.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>第二种则是使用命令行查看</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker search tomcat</span><br></code></pre></td></tr></table></figure>

<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/e5db88e24f47422a910b86baf959a42b.png#">https://img-blog.csdnimg.cn/e5db88e24f47422a910b86baf959a42b.png#</a> &#x3D;80%x)</p>
<p>拉取镜像，这里默认为latest最新版本：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker pull tomcat</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker images tomcat</span><br></code></pre></td></tr></table></figure>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/76237cbcf2a242aeb5f1b11e30a05b74.png#">https://img-blog.csdnimg.cn/76237cbcf2a242aeb5f1b11e30a05b74.png#</a> &#x3D;60%x)</p>
<p><strong>根据tomcat镜像启动容器</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker run -d -p 8080:8080 --name=tomcat_test tomcat</span><br></code></pre></td></tr></table></figure>
<p>相关参数说明：</p>
<blockquote>
<p>-p 小写，用于端口映射，格式为： 主机端口:docker容器端口<br>-P 大写，随机分配容器的端口<br>i：支持交互<br>t：支持终端<br>d：后台运行</p>
</blockquote>
<p>进入tomcat容器内部，替换默认的空目录</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker <span class="hljs-built_in">exec</span> -it tomcat_test /bin/bash</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-built_in">cd</span> /usr/local/tomcat</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-built_in">rm</span> -rf webapps</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-built_in">mv</span> webapps.dist webapps</span><br></code></pre></td></tr></table></figure>

<p>配置好后，访问 <code>http:docker宿主机IP:8080</code></p>
<p>因为之前配置了端口映射，所以直接访问宿主机IP的8080端口，就能映射到该tomcat容器的端口，从而直接访问Tomcat。</p>
<p>注：最新版的tomcat一般不够稳定，兼容性也不如以前的版本，这里根据视频教程切换成了较稳定的，支持JDK8的v8版本</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker pull billygoo/tomcat8-jdk8</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker run -d -p 8080:8080 --name tomcat8 billygoo/tomcat8-jdk8</span> <br></code></pre></td></tr></table></figure>
<p>这个版本不用替换webapp</p>
<h2 id="2-2-Docker-安装-MySQL-5-7"><a href="#2-2-Docker-安装-MySQL-5-7" class="headerlink" title="2.2 Docker  安装 MySQL 5.7"></a>2.2 Docker  安装 MySQL 5.7</h2><p>熟练过后直接pull镜像，如果没有的话，再去docker hub上查找</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker pull mysql:5.7</span><br></code></pre></td></tr></table></figure>
<p>提示：docker hub 上有镜像的使用说明，<a target="_blank" rel="noopener" href="https://registry.hub.docker.com/_/mysql">参考链接</a></p>
<h3 id="2-2-1-简易版安装"><a href="#2-2-1-简易版安装" class="headerlink" title="2.2.1 简易版安装"></a>2.2.1 简易版安装</h3><p>创建并启动容器</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d --name mysql5.7 mysql:5.7</span><br></code></pre></td></tr></table></figure>

<p>进入容器</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker <span class="hljs-built_in">exec</span> -it mysql5.7 /bin/bash</span><br></code></pre></td></tr></table></figure>
<p>启动、连接mysql</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">mysql -uroot -p123456<br></code></pre></td></tr></table></figure>
<p>创建测试的数据并查询</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">mysql&gt; </span><span class="language-bash">create database uni;</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">mysql&gt; </span><span class="language-bash">use uni;</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">mysql&gt; </span><span class="language-bash">create table uni_user(<span class="hljs-built_in">id</span> varchar(11));</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">mysql&gt; </span><span class="language-bash">insert into uni_user values(<span class="hljs-string">&quot;5201314&quot;</span>);</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">mysql&gt; </span><span class="language-bash">select * from uni_user;</span><br></code></pre></td></tr></table></figure>

<p>外部通过宿主机IP和3306端口连接容器的MySQL</p>
<p>测试软件 Navicat15，用其他的能连接MySQL的都行</p>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/c36571d824f74df4ad21549adde711a1.png#">https://img-blog.csdnimg.cn/c36571d824f74df4ad21549adde711a1.png#</a> &#x3D;80%x)</p>
<p>插入一条带中文的数据报错：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">INSERT INTO uni_user(&quot;哈哈哈&quot;);<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/5ed571ccbdac483680e2ae77fa7028e6.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>报错原因：Docker 上默认字符集编码</p>
<p>在 Docker MySQL容器里查询编码格式</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">mysql&gt; </span><span class="language-bash">SHOW VARIABLES LIKE <span class="hljs-string">&#x27;character%&#x27;</span></span><br></code></pre></td></tr></table></figure>

<p>运行结果：<br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/43e3d4b343234fb3a6b1b2df17bec5bf.png#">https://img-blog.csdnimg.cn/43e3d4b343234fb3a6b1b2df17bec5bf.png#</a> &#x3D;60%x)<br>简易版的容器安装，因没有配置容器卷，若容器被删除，那么里面的MySQL数据直接就丢失了。</p>
<p>接下来通过实战版的配置对这两个主要问题进行解决</p>
<h3 id="2-2-2-实战版安装"><a href="#2-2-2-实战版安装" class="headerlink" title="2.2.2 实战版安装"></a>2.2.2 实战版安装</h3><p>将之前的容器强制删除</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">sudo docker rm -f mysql5.7<br></code></pre></td></tr></table></figure>

<p>使用之前pull的mysql:5.7，接下来直接创建容器，挂载三个卷</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker run -d -p 3306:3306 --privileged=<span class="hljs-literal">true</span> \</span><br><span class="language-bash">-v /uni/docker/mysql/log:/var/log/mysql \</span><br><span class="language-bash">-v /uni/docker/mysql/data:/var/lib/mysql \</span><br><span class="language-bash">-v /uni/docker/mysql/conf:/etc/mysql/conf.d \</span><br><span class="language-bash">-e MYSQL_ROOT_PASSWORD=123456 \</span><br><span class="language-bash">--name mysql5.7 \</span><br><span class="language-bash">mysql:5.7</span><br></code></pre></td></tr></table></figure>

<p>新建my.conf，通过容器卷同步给Mysql容器实例</p>
<p>由于第一次进入，容器的&#x2F;etc&#x2F;mysql&#x2F;conf.d是空文件夹，所以在宿主机里可能不显示绑定的conf文件夹，这里先在宿主机直接创建一个，然后再创建MySQL的配置文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo <span class="hljs-built_in">mkdir</span> /uni/mysql/conf</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-built_in">cd</span> /uni/mysql/conf</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo vim my.conf</span><br></code></pre></td></tr></table></figure>

<p>添加的配置内容如下：</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs ini"><span class="hljs-section">[client]</span><br><span class="hljs-attr">default_character_set</span>=utf8<br><span class="hljs-section">[mysqld]</span><br><span class="hljs-attr">collation_server</span>=utf8_general_c<br><span class="hljs-attr">character_set_server</span>=utf8<br></code></pre></td></tr></table></figure>

<p>配置好后需先重启MySQL容器，然后在进去查询编码</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker restart mysql5.7</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker <span class="hljs-built_in">exec</span> -it mysql5.7 bash</span><br><br>mysql -uroot -p123456<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">mysql&gt; </span><span class="language-bash">SHOW VARIABLES LIKE <span class="hljs-string">&#x27;character%&#x27;</span>;</span><br></code></pre></td></tr></table></figure>
<p><strong>查询结果：</strong><br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/6f06014b757e4e26b99d6920fbc1a0d8.png#">https://img-blog.csdnimg.cn/6f06014b757e4e26b99d6920fbc1a0d8.png#</a> &#x3D;60%x)</p>
<p>接下来试试能不能插入中文数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs sql">mysql<span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> database uni;<br>mysql<span class="hljs-operator">&gt;</span> use uni;<br>mysql<span class="hljs-operator">&gt;</span> <span class="hljs-keyword">create</span> <span class="hljs-keyword">table</span> uni_user(id <span class="hljs-type">varchar</span>(<span class="hljs-number">11</span>));<br>mysql<span class="hljs-operator">&gt;</span> <span class="hljs-keyword">insert</span> <span class="hljs-keyword">into</span> uni_user(&quot;哈哈哈&quot;);<br>mysql<span class="hljs-operator">&gt;</span> <span class="hljs-keyword">select</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">from</span> uni_user;<br></code></pre></td></tr></table></figure>
<p>至此，编码问题解决完毕。<br>注：如果将当前的容器实例删除，那么原来宿主机的数据是不会被删除的。</p>
<h2 id="2-3-Docker-安装-Redis"><a href="#2-3-Docker-安装-Redis" class="headerlink" title="2.3 Docker 安装 Redis"></a>2.3 Docker 安装 Redis</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_"># </span><span class="language-bash">查看镜像是否存在</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker search redis</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">从Docker Hub 拉取镜像</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker pull redis:6.0.16</span><br><br>在宿主机创建redis配置文件/etc/redis/redis.conf，使用该配置文件来启动redis容器<br>```shell<br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo <span class="hljs-built_in">mkdir</span> /uni/docker/redis/</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo <span class="hljs-built_in">touch</span> /uni/docker/redis/redis.conf</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo vim /uni/docker/redis/redis.conf</span><br></code></pre></td></tr></table></figure>


<p>配置的相关内容如下，其他默认（配置文件较大，建议从官网压缩包里获取 <a target="_blank" rel="noopener" href="https://download.redis.io/releases/redis-6.0.16.tar.gz">点击下载</a>）：</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs nginx"><span class="hljs-comment"># 1. 开启验证密码为123（手动添加这行）（可选）</span><br><span class="hljs-attribute">requirepass</span> <span class="hljs-number">123</span><br><br><span class="hljs-comment"># 2. 允许外部连接redis，注释掉bind 127.0.0.1</span><br><span class="hljs-comment">#bind 127.0.0.1</span><br><br><span class="hljs-comment"># 3. 必须设置daemonize 为 no，否则会和docker run 的 -d参数冲突</span><br>daemonize <span class="hljs-literal">no</span><br><br><span class="hljs-comment"># 4. 开启redis数据持久化（可选）</span><br>appendonly <span class="hljs-literal">yes</span><br></code></pre></td></tr></table></figure>


<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_"># </span><span class="language-bash">后台运行容器（为数据和配置文件绑定卷）</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker run -p 6379:6379 --name redis6.0.16 --privileged=<span class="hljs-literal">true</span> \</span><br><span class="language-bash">-v /uni/docker/redis/redis.conf:/etc/redis/redis.conf \</span><br><span class="language-bash">-v /uni/docker/redis/data:/data \</span><br><span class="language-bash">-d redis:6.0.16 redis-server /etc/redis/redis.conf</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">进入容器</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker <span class="hljs-built_in">exec</span> -it redis6.0.16 bash</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">在容器内启动redis客户端连接本地容器的服务端</span><br>redis-cli<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">验证密码</span><br>127.0.0.1:6379&gt; auth &quot;123&quot;<br></code></pre></td></tr></table></figure>
<p>接下来进行数据库的切换，以验证修改宿主机里容器卷的配置文件是否有效</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_"># </span><span class="language-bash">切换到15数据库（redis默认有0~15个下标数据库）</span><br>127.0.0.1:6379&gt; select 15<br><span class="hljs-meta prompt_"># </span><span class="language-bash">尝试切换到16，则报错(error) ERR DB index is out of range</span><br>127.0.0.1:6379&gt; select 16<br></code></pre></td></tr></table></figure>

<p>接下来修改宿主机里的redis配置文件&#x2F;uni&#x2F;docker&#x2F;redis&#x2F;redis.conf，替换database 15 为</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs apache"><span class="hljs-attribute">database</span> <span class="hljs-number">10</span><br></code></pre></td></tr></table></figure>

<p>修改后需要重启redis容器</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker restart redis6.0.16</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker <span class="hljs-built_in">exec</span> -it redis6.0.16 bash</span><br><br>redis-cli<br><br>127.0.0.1:6379&gt; auth &quot;123&quot;<br><span class="hljs-meta prompt_"># </span><span class="language-bash">出现报错则说明同步完毕</span><br>127.0.0.1:6379&gt; select 11<br></code></pre></td></tr></table></figure>
<h1 id="参-考-资-料"><a href="#参-考-资-料" class="headerlink" title="参  考  资  料"></a>参  考  资  料</h1><hr>
<p><a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1gr4y1U7CY?p=31">视频链接</a></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/Docker/" class="category-chain-item">Docker</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/Docker/">#Docker</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Docker 笔记1 Volumes 卷的作用与案例 _ Docker安装常见服务 _ Tomcat &amp; MySQL</div>
      <div>http://example.com/2022/04/04/Docker 笔记1 Volumes 卷的作用与案例 _ Docker安装常见服务 _ Tomcat &amp; MySQL/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年4月4日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/04/04/Hive%20%E7%AC%94%E8%AE%B04%20%E6%A1%88%E4%BE%8B%E5%AE%9E%E6%93%8D%20_%20%E7%BB%9F%E8%AE%A1%E5%BD%B1%E8%A7%86%E7%BD%91%E7%AB%99%E7%9A%84%E5%B8%B8%E8%A7%84%E6%8C%87%E6%A0%87%EF%BC%8C%E5%90%84%E7%A7%8D%20TopN%E6%8C%87%E6%A0%87%20_%20%E8%A7%82%E7%9C%8B%E6%95%B0Top10%20_explode%20%E7%82%B8%E8%A3%82%E7%BB%9F%E8%AE%A1%E8%A7%86%E9%A2%91%E7%B1%BB%E5%88%AB%E7%9A%84%E8%A7%82%E7%9C%8B%E6%95%B0%20_%20%E5%B5%8C%E5%A5%97%E5%AD%90%E6%9F%A5%E8%AF%A2/" title="Hive 笔记4 案例实操 _ 统计影视网站的常规指标，各种 TopN指标 _ 观看数Top10 _explode 炸裂统计视频类别的观看数 _ 嵌套子查询">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Hive 笔记4 案例实操 _ 统计影视网站的常规指标，各种 TopN指标 _ 观看数Top10 _explode 炸裂统计视频类别的观看数 _ 嵌套子查询</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/03/31/%E6%9C%88%E5%BA%A6%E6%80%BB%E7%BB%93%20_%202022%E5%B9%B403%E6%9C%88%20_%20%E8%80%83%E7%A0%94%E4%B8%8E%E5%B0%B1%E4%B8%9A%E7%9A%84%E6%8A%89%E6%8B%A9%20_%20%E7%A1%AE%E5%AE%9A%E6%9C%AA%E6%9D%A5%E8%B5%B0%E5%A4%A7%E6%95%B0%E6%8D%AE%E5%BC%80%E5%8F%91%E8%B7%AF%E7%BA%BF/" title="月度总结 _ 2022年03月 _ 考研与就业的抉择 _ 确定未来走大数据开发路线">
                        <span class="hidden-mobile">月度总结 _ 2022年03月 _ 考研与就业的抉择 _ 确定未来走大数据开发路线</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
